package com.mlt.back.web.servlet;

import com.mlt.back.beans.Role;
import com.mlt.back.service.RoleService;
import com.mlt.back.service.impl.RoleServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet({"/back/selectAll"})
public class RoleServlet extends HttpServlet {
    private RoleService roleService=new RoleServiceImpl();
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String servletPath = request.getServletPath();
        request.setCharacterEncoding("utf-8");
        /**
         * chan
         * 全查询,拿到集合
         */
        if ("/back/selectAll".equals(servletPath)){
            doSelectAll(request,response);
        }
    }

    private void doSelectAll(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        List<Role> roleList=roleService.selectAll();
        System.out.println(roleList);
        HttpSession session = request.getSession();
        session.setAttribute("roleList",roleList);
        /*response.sendRedirect(request.getContextPath()+"/admin_manager_list.jsp");*/
        response.sendRedirect(request.getContextPath()+"/back/selectByRole?page=1");
    }
}
